package main

import (
	"fmt"
	"sync"
	"time"
)

func main() {
	var wg sync.WaitGroup

	// 启动 10 个 goroutine
	for i := 1; i <= 10; i++ {
		wg.Add(1)
		go func(i int) {
			defer wg.Done()
			fmt.Printf("Goroutine %d is running\n", i)
			time.Sleep(1 * time.Second) // 模拟一个耗时操作
			fmt.Printf("Goroutine %d is done\n", i)
		}(i)
	}

	// 等待所有 goroutine 完成
	wg.Wait()
	fmt.Println("All goroutines have completed.")
}
